package com.qf.controller;

import com.qf.dao.impl.AdminDaoImpl;
import com.qf.pojo.User;
import com.qf.service.AdminService;
import com.qf.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 根据用户id获取用户信息后台
 */
@WebServlet("/findUser")
public class FindUserServlet extends HttpServlet {


    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //1)接收参数
        //  <a href="${pageContext.request.contextPath}/findUser?uid=${uid}"
        String uid = request.getParameter("uid");
        //2)调用业务接口
        AdminService adminService = new AdminServiceImpl() ;
        User user = adminService.getUser(uid);

        //System.out.println(user);

        //3)将user对象存储在request域中
        request.setAttribute("user",user);
        //4)请求转发到修改页面上
        request.getRequestDispatcher("/admin/user_update.jsp").forward(request,response);

    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request,response);
    }
}
